<?php
namespace Manage\Model;
use Think\Model;
class ModuleModel extends Model{
	public function operModule($data,$code,$module_id=0){
		$featured=array(
			'code'		=>	$code,
			'name'		=>	$data['name'],
			'setting'	=>	json_encode($data)
			);
		if($module_id){
			$map['module_id']=$module_id;
			$this->where($map)->save($featured);
		}else{
			$this->add($featured);
		}

	}
	public function getModuleById($module_id){
		return $this->where(array('module_id'=>$module_id))->find();
	}
	public function getModulesByCode($code){
		return $this->where(array('code'=>$code))->order('module_id desc')->select();
	} 
	public function deleteModule($module_id){
		return $this->where(array('module_id'=>(int)$module_id))->delete();
	}
}